# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

DESCRIPTION="HP Linux Imaging and Printing System. Includes net-print/hpijs, scanner drivers and service tools."
HOMEPAGE="http://hpinkjet.sourceforge.net/"
SRC_URI="mirror://sourceforge/hpinkjet/${P}.tar.gz"
LICENSE="GPL MIT BSD"
SLOT="0"
KEYWORDS="~x86"
#IUSE="cups foomaticdb network X"
IUSE="foomaticdb network X"

# !net-print/hpijs - as this package contains hpijs (but which version? :/)
DEPEND="
	>=dev-lang/python-2.2.0
	!net-print/hpijs
	>=net-print/cups-1.1.18-r2
	network? ( >=net-analyzer/net-snmp-5.0.9 )"

RDEPEND="
	>=app-text/ghostscript-7.05
	foomaticdb? ( >=net-print/foomatic-db-engine-3.0.2
	              >=net-print/foomatic-filters-3.0.2 )
	X? ( >=dev-python/PyQt-3.11 )"

src_unpack() {
	unpack ${A}

	cd ${WORKDIR}
 	# fixes a the bug mentioned here:
	# http://sourceforge.net/forum/forum.php?thread_id=1259523&forum_id=53438
	# epatch ${FILESDIR}/hplip-0.9.1-qsizepolicy-patch
	# -> fixed in 0.9.2
}

src_compile() {
	# cups is build-time dependency no matter if you --disable-cups-install
	#  or --enable.. it (is it a bug to report upstream? :/)
	#  so we leave the default ./configure setting of --enable-cups-install
	#  (but is it the Gentoo-way :/)
	#use cups || EXTRA_ECONF="${EXTRA_ECONF} --disable-cups-install"	
	use foomaticdb || EXTRA_ECONF="${EXTRA_ECONF} --disable-foomatic-install"
	use network || EXTRA_ECONF="${EXTRA_ECONF} --disable-network-build"
	echo EXTRA_CONF
	econf || die "Error: econf failed!"

	emake || die "Error: emake failed!"
}


src_install() {
	# this should work now (since hplip-0.9.0.2)
	make install DESTDIR=${D}
	
	# install Gentoo-specific init script
	exeinto /etc/init.d
	newexe ${FILESDIR}/hplip.init.d hplip

	# for scanner support:
	insinto /etc/sane.d
	echo "hpaio" > dll.conf
	doins dll.conf
	
	dodir /usr/lib/sane
	dosym /usr/lib/libsane-hpaio.la /usr/lib/sane/libsane-hpaio.la
	dosym /usr/lib/libsane-hpaio.so /usr/lib/sane/libsane-hpaio.so
	dosym /usr/lib/libsane-hpaio.so.1 /usr/lib/sane/libsane-hpaio.so.1
	dosym /usr/lib/libsane-hpaio.so.1.0.0 /usr/lib/sane/libsane-hpaio.so.1.0.0
}
